package com.fluidops.datacatalog.reltables.util;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;

public class LRUCache<K, V>  implements Serializable,Map<K, V> {

	private static final long serialVersionUID = -2320403694137977435L;

	private Map<K, V> cache;
	
	
	public LRUCache(final int maxSize){
		this.cache = new LinkedHashMap<K, V> (maxSize + 1, 0.75f, true){

			private static final long serialVersionUID = 1813637315930913197L;

			@Override
			protected boolean removeEldestEntry(Map.Entry<K, V> eldest)
			{
				return size() > maxSize;
			}
		};
	}

	@Override
	public void clear() {
		this.cache.clear();
	}


	@Override
	public boolean containsKey(Object arg0) {
		return this.cache.containsKey(arg0);
	}


	@Override
	public boolean containsValue(Object arg0) {
		return this.cache.containsValue(arg0);
	}


	@Override
	public Set<java.util.Map.Entry<K, V>> entrySet() {
		return this.cache.entrySet();
	}


	@Override
	public V get(Object arg0) {
		return this.cache.get(arg0);
	}


	@Override
	public boolean isEmpty() {
		return this.cache.isEmpty();
	}


	@Override
	public Set<K> keySet() {
		return this.cache.keySet();
	}


	@Override
	public V put(K arg0, V arg1) {
		return this.cache.put(arg0, arg1);
	}


	@Override
	public void putAll(Map<? extends K, ? extends V> arg0) {
		this.cache.putAll(arg0);
	}


	@Override
	public V remove(Object arg0) {
		return this.cache.remove(arg0);
	}


	@Override
	public int size() {
		return this.cache.size();
	}


	@Override
	public Collection<V> values() {
		return this.cache.values();
	}
	
	
}
